package com.example.ole.taskqueue.Q.base;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * PriorityBlockingQueue is not bounded. Here we create the boundary.
 *
 * @param <E>
 */
public class PrioritizedBlockingQueueLimitBoundary<E> extends PriorityBlockingQueue {
    private int mCapacityLimitation;

    public PrioritizedBlockingQueueLimitBoundary(int capacity) {
        super(capacity);
        mCapacityLimitation = capacity;
    }

    @Override
    public boolean offer(Object o) {
        if (size() >= mCapacityLimitation)
            return false;

        return super.offer(o);
    }
}
